package GUI;
/**hofit**/
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import Client.BusinessImplements;
import Controler.Member_Card_Controler;
import DAL.Member_DAL;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Color;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.border.LineBorder;

public class Update_Member_Card_Primary extends Abstract_Jpanel {
	private final JLabel lblChooseUser = new JLabel("Choose user:");
	private final JLabel lblId = new JLabel("User ID:");
	private final JTextField txtID = new JTextField();
	public JButton btnSearch = new JButton("Search");
	private final JPanel panel = new JPanel();
	public final JButton btnBack = new JButton("Back");
	private final JLabel lblChooseUserId = new JLabel("choose user id of the member that you like to update his detaels");

	/**
	 * Create the panel.
	 */
	public Update_Member_Card_Primary() {
		txtID.setBounds(103, 37, 239, 20);
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.add(txtID);
		txtID.setColumns(10);

		initGUI();
	}
	private void initGUI() {
		setLayout(null);
		panel.setBounds(12, 58, 505, 205);
		
		add(panel);
		panel.setLayout(null);
		lblId.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblId.setBounds(25, 38, 68, 15);
		panel.add(lblId);
		lblChooseUserId.setForeground(Color.RED);
		lblChooseUserId.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		lblChooseUserId.setBounds(25, 68, 441, 37);
		
		panel.add(lblChooseUserId);
		lblChooseUser.setForeground(new Color(25, 25, 112));
		lblChooseUser.setBounds(26, 11, 255, 36);
		add(lblChooseUser);
		lblChooseUser.setFont(new Font("MV Boli", Font.BOLD, 30));
		btnSearch.setBounds(406, 289, 96, 41);
		add(btnSearch);
		btnSearch.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnBack.setBounds(35, 289, 89, 40);
		add(btnBack);
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();
				
			}
		});
		/**
		 * check if the member exist if not pop up message 
		 * if the member exist set the details on the next screen
		 */
		btnSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Managment_panel mangment_panel=new Managment_panel();
				Member_Card_Controler member=new Member_Card_Controler();
				Member_DAL mem=member.checkID(txtID.getText());
				if (mem!=null)
				{
					ArrayList<String> details=new ArrayList<>();
					details=BusinessImplements.GetInstance().getServerProxy().getUserdetails(txtID.getText());
					String password=details.get(2);
					mangment_panel.update_memmber_details_sec.setData(mem, txtID.getText(), password);
					on_screen_unload();
					BusinessImplements.GetInstance().getMainFrame().setContentPane(mangment_panel.update_memmber_details_sec);
					mangment_panel.update_memmber_details_sec.setSize(getMaximumSize());
					mangment_panel.update_memmber_details_sec.on_screen_load();
				}
				else
					JOptionPane.showMessageDialog(null, "The user not exist in the system!");
				
				
				
			}
		});
	}
	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * if the privilage is user disable the option to choose another id and set his id in the text box
	 */
	@Override
	public void on_screen_load() {
		if (BusinessImplements.GetInstance().getUserLogin().getUserPosition()==1)
		{
			txtID.setEditable(false);
			txtID.setText(Integer.toString(BusinessImplements.GetInstance().getUserLogin().getUserID()));
		}
		else
			txtID.setEditable(true);
	}
	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
}
